# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

head=ListNode(1,None)
head.next=ListNode(1,None)
head.next.next=ListNode(3,None)
head.next.next.next=ListNode(3,None)
head.next.next.next.next=ListNode(4,None)
head.next.next.next.next.next=ListNode(4,None)
head.next.next.next.next.next.next=ListNode(5,None)
head.next.next.next.next.next.next.next=ListNode(6,None)

def deleteDuplicates(head):

    if head==None or (head and head.next==None):
        #空链表的情况或者只有一个元素存在的链表
        return head
    headProcess=head
    headProcessNext=head.next
    toolNums=[]
    while headProcess!=None and headProcessNext!=None:
        if headProcess.val == headProcessNext.val:
            toolNums.append(headProcess.val)
        headProcess=headProcessNext
        headProcessNext=headProcessNext.next
    print(toolNums)
    toolNums=set(toolNums)
    #考虑头结点是重复节点的情况
    while head.val in toolNums:
        head=head.next
    if head and head.next:
        headProcess=head
        headProcessNext=head.next
        while headProcess!=None and headProcessNext!=None:
            if headProcessNext.val in toolNums:
                headProcess.next=headProcessNext.next
                headProcessNext=headProcess.next
            else:
                headProcess=headProcess.next
                headProcessNext=headProcessNext.next

    headProcess=head
    while headProcess:
        print(headProcess.val)
        headProcess=headProcess.next
    return head

deleteDuplicates(head)


